/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "MudCreatureConductorTask.h"

#include "Room.h"
#include "config.h"
#include "MudCreature.h"
#include "MudPlayer.h"
#include "CmdVisitor.h"
#include "MudObject.h"
#include "Utils.h"

using namespace std;
using namespace Chronos;

MudCreatureConductorTask::MudCreatureConductorTask(MudCreature& conductor)
    : MudObjectTask<MudCreature>(conductor)
	, state(LOOKING)
{}


unsigned int MudCreatureConductorTask::run2() {
    if (object->isInCombat()) return seconds(10);

    Room* room = object->getRoom();
	switch(state) {
	case LOOKING:
		room->showText("The conductor looks around for persons to check.");
		state = CHECKING;
		return seconds(5);
	case CHECKING:
		checkRoom();
		state = LOOKING;
		return seconds(15);
	}
	return 0;
}


void MudCreatureConductorTask::checkRoom() {
    Room* room = object->getRoom();
    MudPlayer* player = room->getFirstPlayer();
    if (player != 0) {
		player->write("The conductor walks towards you and asks for your ticket.\n");
		room->showText("The conductor checks bas for his ticket.", *player);
	}
}

